<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<%@page import="com.wre.jdbc.WreUserDaoImpl"%>
<%@page import="com.wre.factory.WreUserDaoFactory"%>
<%@page import="com.wre.dao.WreUserDao"%>
<%@page import="com.wre.dto.WreUser"%>
<%@page import="com.wre.dao.PropertyDao"%>
<%@page import="com.wre.factory.PropertyDaoFactory"%>
<%@page import="com.wre.dto.Property"%><html xmlns="http://www.w3.org/1999/xhtml">
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
WreUser wreUser=new WreUser();
String userType=(String)session.getAttribute("userType");			
	if(userType == null)
	{
		response.sendRedirect("index.jsp");
		return;
	}
	else if(!userType.equalsIgnoreCase("admin"))
	{
		session.setAttribute("errorMessage", "You don't have sufficient priviliges to access this page.");
		response.sendRedirect("error.jsp");
	}

%>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title> Administration </title>
<link href="default.css" rel="stylesheet" type="text/css" media="screen" />

<link type="text/css" href="css/blitzer/jquery-ui-1.8.13.custom.css" rel="stylesheet" />	
		<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
		<script type="text/javascript" src="js/jquery-ui-1.8.13.custom.min.js"></script>
		<script type="text/javascript">
			$(function(){
				
				// block user dialog			
				$('#blockUser').dialog({
					autoOpen: false,
					title:"Block User",
					width: 510,
					
					buttons: {
						"Ok": function() { 
					var userId=document.getElementById("blockUserId").value;
					
						$.ajax({							
						   url: "<%=basePath%>blockUserPropertyServlet",
						   data:"tableName=wre_user&column=user_id&status=Y&userId="+userId,
						   type:"POST",
						   success: function(data)
						   {							   
							 if(data=="success") 
							 {								
								 //$("#"+userId+"").remove();
								 //$("#blockUserId > option[value='"+userId+"']").remove();
								 alert("User Blocked Successfully........");
								 $('#blockUser').dialog("close"); 
								 window.location.reload();
							 }
							 else
							 {
								 alert("User Blocked Failed...!");
								 $('#blockUser').dialog("close"); 
							 }
							},
							error: function()
							{
								alert("ajax request failed");
								$('#blockUser').dialog("close");
							}
												   
						 });

					 
						}, 
						"Cancel": function() { 
							$(this).dialog("close"); 
						} 
					}
				});

				// un-block user dialog
				$('#unBlockUser').dialog({
					autoOpen: false,
					title:"Un-Block User",
					width: 510,
					
					buttons: {
						"Ok": function() { 
							var unBlockUserId=document.getElementById("unBlockUserId").value;
							$.ajax({							
								   url: "<%=basePath%>blockUserPropertyServlet",
								   data:"tableName=wre_user&column=user_id&status=N&userId="+unBlockUserId,
								   type:"POST",
								   success: function(data)
								   {							   
									 if(data=="success") 
									 {
										 alert("User Un-Blocked Successfully........");
										 $('#unBlockUser').dialog("close"); 
										 window.location.reload();
									 }
									 else
									 {
										 alert("User Un-Blocked Failed...!");
										 $('#unBlockUser').dialog("close"); 										 
									 }
									},
									error: function()
									{
										alert("ajax request failed");
										 $('#unBlockUser').dialog("close"); 
									}
														   
								 });							
						}, 
						"Cancel": function() { 
							$(this).dialog("close"); 
						} 
					}
				});

				// block property dialog			
				$('#blockProperty').dialog({
					autoOpen: false,
					title:"Block Property",
					width: 510,
					
					buttons: {
						"Ok": function() { 
					var propertyId=document.getElementById("blockPropertyId").value;
					$.ajax({							
						   url: "<%=basePath%>blockUserPropertyServlet",
						   data:"tableName=property&column=property_id&status=Y&userId="+propertyId,
						   type:"POST",
						   success: function(data)
						   {							   
							 if(data=="success") 
							 {								 							
								 alert("Property Blocked Successfully........");
								 $('#blockProperty').dialog("close"); 
								 window.location.reload();
								 
							 }
							 else
							 {
								 alert("Property Blocked Failed...!");
								 $('#blockProperty').dialog("close"); 
							 }
							},
							error: function()
							{
								alert("ajax request failed");
								$('#blockProperty').dialog("close"); 
							}
												   
						 });
						}, 
						"Cancel": function() { 
							$(this).dialog("close"); 
						} 
					}
				});

				// un-block property dialog
				$('#unBlockProperty').dialog({
					autoOpen: false,
					title:"Un-Block Property",
					width: 510,
					
					buttons: {
						"Ok": function() { 
					var unBlockPropertyId=document.getElementById("unBlockPropertyId").value;
					$.ajax({							
						   url: "<%=basePath%>blockUserPropertyServlet",
						   data:"tableName=property&column=property_id&status=N&userId="+unBlockPropertyId,
						   type:"POST",
						   success: function(data)
						   {							   
							 if(data=="success") 
							 {						
								 alert("Property Un-Blocked Successfully........");
								 $('#unBlockProperty').dialog("close"); 
								 window.location.reload();
							 }
							 else
							 {
								 alert("Property Un-Blocked Failed...!");
								 $('#unBlockProperty').dialog("close"); 
							 }
							},
							error: function()
							{
								alert("ajax request failed");
								$('#unBlockProperty').dialog("close"); 
							}
												   
						 });
						}, 
						"Cancel": function() { 
							$(this).dialog("close"); 
						} 
					}
				});


				
				
				// Dialog Link
				$('#button_block_user').click(function(){
					$('#blockUser').dialog('open');
					return false;
				});
				
				//hover states on the static widgets
				$('#button_block_user, ul#icons li').hover(
					function() { $(this).addClass('ui-state-hover'); }, 
					function() { $(this).removeClass('ui-state-hover'); }
				);

				// Dialog Link
				$('#button_un_block_user').click(function(){
					$('#unBlockUser').dialog('open');
					return false;
				});
				
				//hover states on the static widgets
				$('#button_un_block_user, ul#icons li').hover(
					function() { $(this).addClass('ui-state-hover'); }, 
					function() { $(this).removeClass('ui-state-hover'); }
				);

				// Dialog Link
				$('#button_block_property').click(function(){
					$('#blockProperty').dialog('open');
					return false;
				});
				
				//hover states on the static widgets
				$('#button_block_property, ul#icons li').hover(
					function() { $(this).addClass('ui-state-hover'); }, 
					function() { $(this).removeClass('ui-state-hover'); }
				);

				// Dialog Link
				$('#button_un_block_property').click(function(){
					$('#unBlockProperty').dialog('open');
					return false;
				});
				
				//hover states on the static widgets
				$('#button_un_block_property, ul#icons li').hover(
					function() { $(this).addClass('ui-state-hover'); }, 
					function() { $(this).removeClass('ui-state-hover'); }
				);
				
			});
		</script>

</head>
<body>

<jsp:include page="/header.jsp" />

<div id="wrapper">
	<!-- start page -->
	<div id="page">
		<jsp:include page="/sideMenuLeft.jsp" />
		<!-- start content -->
		<div id="content">			
			<div class="post">
				<h1 class="title"><a href="#">Administration</a></h1>
				<p class="byline"><br ></p>
				<div class="entry">
					
					<button id="button_block_user">Block user</button>
					<button id="button_un_block_user">Unblock user</button>
					<button id="button_block_property">Block Property</button>
					<button id="button_un_block_property">Unblock Property</button>
					
					
					
										
					
				</div>
			</div>
			
		</div>
		<!-- end content -->
		<!-- start sidebars -->
		<jsp:include page="/sideMenuRight.jsp" />
		<!-- end sidebars -->
		<div style="clear: both;">&nbsp;</div>
	</div>
	<!-- end page -->
</div>
<jsp:include page="/footer.jsp" />

<!-- Block User Dialog -->
<div id="blockUser" style="display: none;">

Select user : 
<select id="blockUserId">
<option value="--select--">--select--</option>
<%
WreUserDao usersDao= WreUserDaoFactory.create();
WreUser[] users=usersDao.findByDynamicWhere("is_deprecated=?", new Object[]{"N"});

for( WreUser user: users)
{
%>
<option value="<%=user.getUserId() %>"><%=user.getFirstName() %></option>
<%
	
}
%>
</select>

</div>
<!-- Un-Block Property Dialog -->

<div id="unBlockUser" style="display: none;">
Select User : 
<select id="unBlockUserId">
<option value="--select--">--select--</option>
<%
	usersDao= WreUserDaoFactory.create();
	users=usersDao.findByDynamicWhere("is_deprecated=?", new Object[]{"Y"});

for( WreUser user: users)
{
%>
<option value="<%=user.getUserId() %>"><%=user.getFirstName() %></option>
<%
	
}
%>
</select>
</div>

<!-- Block Property Dialog -->
<div id="blockProperty" style="display: none;">
Select Property :
<select id="blockPropertyId">
<option value="--select--">--select--</option>
<%
	PropertyDao propertyDao = PropertyDaoFactory.create();
	Property[] properties=propertyDao.findByDynamicWhere("is_deprecated=?", new Object[]{"N"});
	
for( Property property: properties)
{
%>
<option value="<%=property.getPropertyId() %>"><%=property.getPropertyName() %></option>
<%
	
}
%>
</select>

</div>

<!-- Un-Block Property Dialog -->
<div id="unBlockProperty" style="display: none;">
Select Property :
<select id="unBlockPropertyId">
<option value="--select--">--select--</option>
<%
	propertyDao = PropertyDaoFactory.create();
	properties=propertyDao.findByDynamicWhere("is_deprecated=?", new Object[]{"Y"});
	
for( Property property: properties)
{
%>
<option value="<%=property.getPropertyId() %>"><%=property.getPropertyName() %></option>
<%
	
}
%>
</select>
</div>

</body>
</html>